package main

import (
	"fmt"
)

func main() {
	/*
		练习题 1:
			写一个程序，统计一个字符串中每个单词出现的次数。
			比如：”how do you do”中how=1 do=2 you=1
	*/
	s := "how do you do"
	m := make(map[string]int)
	x := 0
	for i := 0; i <= len(s); i++ {
		if i == len(s) || s[i] == ' ' {
			key := string(s[x:i])
			x = i + 1
			m[key] += 1
		}
	}
	for key, value := range m {
		fmt.Println(key, value)
	}

	fmt.Println("-----------------------------------------------")

	/*
		练习题 2:
			观察下面代码，写出最终的打印结果。
			func main() {
				type Map map[string][]int
				m := make(Map)
				s := []int{1, 2}
				s = append(s, 3)
				fmt.Printf("%+v\n", s)
				m["q1mi"] = s
				s = append(s[:1], s[2:]...)
				fmt.Printf("%+v\n", s)
				fmt.Printf("%+v\n", m["q1mi"])
			}
	*/
	type Map map[string][]int
	m1 := make(Map)
	s1 := []int{1, 2}
	s1 = append(s1, 3)
	fmt.Printf("%+v\n", s1)
	m1["q1mi"] = s1
	s1 = append(s1[:1], s1[2:]...)
	fmt.Printf("%+v\n", s1)
	fmt.Printf("%+v\n", m1["q1mi"])
	/*结果：
	[1 2 3]
	[1 3]
	[1 3 3]
	*/

}
